package unitTest;
import java.io.UnsupportedEncodingException;

import utils.*;

import crypto.*;
/**
 * unit-test class for crypto package
 * @author yuvalshu
 *
 */
public class CryptObjectsTester {
	/**
	 * @param args
	 * @throws UnsupportedEncodingException 
	 */
	public static void main(String[] args) throws UnsupportedEncodingException {
		String input = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f";
		String input48 = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f";
		String input64 = "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f";
		checkPRG(input, "SHA-256", 128);
		checkPRG(input48, "SHA-384", 128);
		checkPRG(input64, "SHA-512", 128);
		checkRO(input,"SHA-256",65);
		checkRO(input,"SHA-256",261);
		checkRO(input,"SHA-384",93);
		checkRO(input,"SHA-384",411);
		checkRO(input,"SHA-512",111);
		checkRO(input,"SHA-512",579);
		
	}
	public static void checkPRG(String input,String hash,int nOut) throws UnsupportedEncodingException{
		HashFunction hashFunc = new HashFunction(hash);
		PRG prg = new PRG(hashFunc);
		byte[] seedArray = ByteArrUtils.hexStringToByteArray(input);
		
		prg.setSeed(seedArray);
		byte[] bRes = prg.runPRG(nOut);

		String result = ByteArrUtils.ByteArrayToHexString(bRes);
		System.out.println("the result of PRG is");
		System.out.println(result);
	}
	
	public static void checkRO(String input,String hash, int nOut) throws UnsupportedEncodingException{
		byte[] seedArray = ByteArrUtils.hexStringToByteArray(input);
		
		RandomOracle RO = new RandomOracle(new HashFunction(hash), nOut);
		byte[] bRes = RO.runRandomOracle(seedArray);
		
		String result = ByteArrUtils.ByteArrayToHexString(bRes);
		System.out.println("the result of RO is");
		System.out.println(result);
	}
}
